#include "stklevelitem.h"
#include "ui_stklevelitem.h"


StkLevelItem::StkLevelItem(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::StkLevelItem)
{
    ui->setupUi(this);
}

StkLevelItem::~StkLevelItem()
{
    delete ui;
}

void StkLevelItem::update( std::shared_ptr<bid_ask_item_t> item, bool type) {
    QPalette pal(this->palette());
    QString sPriceStyle = "font-family: \"Microsoft YaHei\";  color: #00A843;";
    if(type) {
        ui->lblNo->setStyleSheet("font-family: \"Microsoft YaHei\"; font-size: 12px; color: #FEF9F9; background-color: #F13E3A;");
        if(item->index == "1")
            pal.setColor(QPalette::Background, QColor("#FDEFEF"));
        else
            pal.setColor(QPalette::Background, QColor("#FEF9F9"));

    }
    else {
        if(item->index == "1")
            pal.setColor(QPalette::Background, QColor("#EAF8EF"));
        else
            pal.setColor(QPalette::Background, QColor("#F7FCF9"));

        ui->lblNo->setStyleSheet("font-family: \"Microsoft YaHei\"; font-size: 12px; color: #FEF9F9; background-color: #00A843;");
    }
    this->setAutoFillBackground(true);
    this->setPalette(pal);

    ui->lblNo->setText(item->index);
    ui->lblPrice->setText(item->mPrice);
    if(item->index == "1") sPriceStyle += "font-weight: bold;";
    ui->lblPrice->setStyleSheet(sPriceStyle);
    QString sQty =  QString::number((item->mQty.toDouble() / 1000.0),'f', 1) + "K";
    ui->lblQty->setText(sQty + "(");
    ui->lblBrokerNum->setText(item->mBrokerNum + ")");
}
